﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cuce.ReportingServices
{
    /// <summary>
    /// 
    /// </summary>
    public class ReportName
    {

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name
        {
            get
            {
                return mName;
            }
        }

        /// <summary>
        /// Gets or sets the folder.
        /// </summary>
        /// <value>The folder.</value>
        public string Folder
        {
            get
            {
                return mFolder.Replace(@"///", @"/").Replace(@"//", @"/");

            }
        }

        private string mFolder;
        private string mName;

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return Folder + Name; 
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="ReportName"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="folder">The folder.</param>
        public ReportName(string name, string folder)
        {
            this.SetName(name, folder);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ReportName"/> class.
        /// </summary>
        public ReportName()
        {
          
        }

        /// <summary>
        /// Sets the name.
        /// </summary>
        /// <param name="longName">The long name.</param>
        public void SetName(string longName)
        {


            int charLocation = longName.LastIndexOf("/") + 1;

            string newName = longName.Substring(charLocation);
            string newFolder = longName.Substring(0, charLocation);

            if (string.IsNullOrEmpty(newName))
                throw new ArgumentException("No Report Name", "reportName");

           // if (string.IsNullOrEmpty(newFolder))
            //    throw new ArgumentException("No Folder Name", "reportName");

            //start with /, end with /
            if (newFolder[0] != '/')
                throw new ArgumentException("Folder name not correct", "folderName");

            //if (newFolder[newFolder.Length - 1] != '/')
            //    throw new ArgumentException("Folder name not correct", "folderName");



            mFolder = newFolder;
            mName = newName;
         
        }



        /// <summary>
        /// Sets the name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="folder">The folder.</param>
        public void SetName(string name, string folder)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException("No Report Name", "name");

            if (string.IsNullOrEmpty(folder))
                throw new ArgumentException("No Folder Name", "folder");


            if (folder[0] != '/')
                throw new ArgumentException("Folder name not correct", "folderName");

            if (folder[folder.Length - 1] != '/')
                throw new ArgumentException("Folder name not correct", "folderName");

          
            
            mName = name;
            mFolder = folder;

        }

    }
}
